package com.dd.logistics.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger;
import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderNumberGenerator {
    private static final AtomicInteger SEQ = new AtomicInteger(1);
    private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    
    public static String generateInboundNumber() {
        return "IN" + generateNumber();
    }
    
    public static String generateOutboundNumber() {
        return "OUT" + generateNumber();
    }
    
    private static String generateNumber() {
        LocalDateTime now = LocalDateTime.now();
        if (SEQ.get() > 9999) {
            SEQ.set(1);
        }
        return DATE_FORMAT.format(now) + String.format("%04d", SEQ.getAndIncrement());
    }
    
    /**
     * 生成库存历史记录编号
     * 格式：IH + 年月日时分秒 + 4位随机数
     */
    public static String generateInventoryHistoryNumber() {
        return "IH" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) 
                + String.format("%04d", (int)(Math.random() * 10000));
    }
} 